package gao.xiaolei.util;

import org.springframework.stereotype.Component;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

@Component("GsonUtil")
public class GsonUtil {

	public Gson getGsonBuilder(String[] fields) {
		Gson gson = new GsonBuilder().setExclusionStrategies(
				new ExclusionStrategy() {
					@Override
					public boolean shouldSkipField(FieldAttributes f) {
						boolean flag = false;
						for (String field : fields) {
							flag = f.getName().contains(field);
							if (flag == true)
								break;
						}
						return flag;
					}

					@Override
					public boolean shouldSkipClass(Class<?> clazz) {
						return false;
					}
				}).create();
		return gson;
	}
}
